<template>
	<view class="container">
		<!-- 顶部选项卡 -->
		<view class="swiper-tab dis-flex box-align-center flex-y-center">
			<block v-for="(item, index) in tabList" :key="index">
				<view class="swiper-tab-item flex-box" :class="{ on: current == index }" :data-index="index" @tap="swichNav">{{ item.text }}({{ item.total }})</view>
			</block>
		</view>
		<!-- 团队总人数 -->
		<view class="widget-people f-28 col-9">团队总人数：{{ tabList[current].total || 0 }}人</view>
		<!-- 我的团队列表 -->
		<mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :height="swiperHeight + 'px'">
			<view class="widget-detail dis-flex flex-x-between" v-for="(item, index) in teamList" :key="index">
				<view class="detail-left dis-flex flex-y-center">
					<view class="user-avatar"><image :src="item.user.avatar"></image></view>
					<view class="user-info dis-flex flex-dir-column flex-x-center">
						<view class="user-nickName f-28">{{ item.user.nickName }}</view>
						<view class="user-time col-9 f-24">{{ item.create_time }}</view>
					</view>
				</view>
				<view class="detail-right dis-flex flex-dir-column flex-x-center flex-y-center">
					<view class="detail-money">
						<text class="f-24">￥</text>
						<text class="f-34">{{ item.user.expend_money }}</text>
					</view>
					<view class="detail-member f-22" v-if="item.dealer">{{ item.dealer.team_num }}个成员</view>
				</view>
			</view>
		</mescroll-body>
	</view>
</template>

<script>
import MescrollMixin from '@/components/mescroll-uni/mescroll-mixins.js';
export default {
	mixins: [MescrollMixin], // 使用mixin
	data() {
		return {
			current: 0,
			teamList: [],
			tabList: [
				{
					value: '-1',
					text: '全部',
					total: 0
				},
				{
					value: '1',
					text: '一级团队',
					total: 0
				},
				{
					value: '2',
					text: '二级团队',
					total: 0
				}
			],
			swiperHeight: null,
		};
	},
	onLoad() {
		this.setSwiperHeight();
	},
	methods: {
		upCallback(mescroll) {
			this.$u.api.getDealerTeamList(this.tabList[this.current].value, mescroll.num).then(res => {
				const { dealer, list } = res.data;
				this.$set(this.tabList[0], 'total', dealer.first_num + dealer.second_num);
				this.$set(this.tabList[1], 'total', dealer.first_num);
				this.$set(this.tabList[2], 'total', dealer.second_num);
				if (mescroll.num == 1) {
					this.teamList = list.data;
				} else {
					this.teamList.push(...list.data);
				}
				this.mescroll.endBySize(list.data.length, list.total);
			});
		},

		/**
		 * 创建页面数据
		 */
		createData(data, isNextPage) {
			data['isLoading'] = false;
			// 列表数据
			let dataList = this.list;
			if (isNextPage == true && typeof dataList !== 'undefined') {
				data.list.data = dataList.data.concat(data.list.data);
			}
			return data;
		},
		/**
		 * 设置swiper的高度
		 */
		setSwiperHeight() {
			// 获取系统信息(拿到屏幕宽度)
			let systemInfo = wx.getSystemInfoSync();
			let tapHeight = uni.upx2px(82); // tap高度
			let peopleHeight = uni.upx2px(65); // people高度
			let swiperHeight = systemInfo.windowHeight - tapHeight - peopleHeight; // swiper高度
			this.swiperHeight = swiperHeight;
		},
		/**
		 * 点击tab切换
		 */
		swichNav(e) {
			this.current = e.target.dataset.index;
			this.$nextTick(() => {
				this.mescroll.resetUpScroll(true);
			});
		}
	}
};
</script>

<style>
page {
	background: #fff;
}

/* 选项卡 */

.swiper-tab {
	width: 100%;
	text-align: center;
	height: 80rpx;
	background-color: #fff;
	border-bottom: 1px solid #eee;
}

.swiper-tab .swiper-tab-item {
	/* width: 33.333333%; */
	height: 100%;
	font-size: 28rpx;
	color: #777;
	display: flex;
	justify-content: center;
	align-items: center;
	box-sizing: border-box;
	border-bottom: 2px solid #ffffff00;
}

.swiper-tab .on {
	color: #786cff;
	border-bottom: 2px solid #786cff;
}

/* 设置scroll-view容器高度 */

.widget-list,
.yoshop-notcont {
	height: 100.1%;
}

/* 团队人数 */

.widget-people {
	padding: 15rpx 25rpx;
	height: 65rpx;
	box-sizing: border-box;
	background: #f7f7f7;
}

/* 提现明细列表 */

.widget-list {
	padding: 10rpx 20rpx 40rpx 20rpx;
	box-sizing: border-box;
}

.widget-detail {
	padding: 20rpx 15rpx;
	box-sizing: border-box;
	font-size: 28rpx;
	border-bottom: 1rpx solid #e7e7e7;
}

.widget-detail .user-avatar {
	margin-right: 16rpx;
}

.widget-detail .user-avatar image {
	display: block;
	width: 100rpx;
	height: 100rpx;
	border: 4rpx solid #fff;
	border-radius: 50%;
}

.widget-detail .user-info {
	height: 100%;
}

.widget-detail .user-nickName {
	margin-bottom: 8rpx;
}

.widget-detail .detail-member {
	background-color: #786cff;
	color: #fff;
	padding: 2rpx 15rpx;
	border-radius: 6rpx;
	margin-top: 10rpx;
}
</style>
